import { http } from "@/utils/http";

export const usePlaylistAPI = () => {
  // 获取推荐歌单
  const getRecommendPlaylists = (): any => {
    return http.get("/music/playlists/recommend");
  };
  const postCreatePlaylist = (
    name: string,
    description: string,
    userId: string,
    isPublic: boolean
  ): any => {
    return http.post("/music/playlists/createPlaylist", {
      name: name,
      description: description,
      userId: userId,
      musicIds: [],
      isPublic: isPublic ? 1 : 0,
    });
  };

  const getFavoritePlaylist = (userId?: string): any => {
    return http.get(`/music/playlist/favorite/list?userId=${userId}`);
  };

  const getUserPlaylists = (userId: string): any => {
    return http.get(`/music/playlists/userid/${userId}`);
  };

  const getPlaylistDetail = (playlistId: string): any => {
    return http.get(`/music/playlists/${playlistId}`);
  };

  const postAddToFavorite = (userId: string, playlistId: string): any => {
    return http.post(
      `/music/playlist/favorite/add?userId=${userId}&playlistId=${playlistId}`
    );
  };

  const postRemoveFromFavorite = (userId: string, playlistId: string): any => {
    return http.post(
      `/music/playlist/favorite/remove?userId=${userId}&playlistId=${playlistId}`
    );
  };

  const checkIsFavorite = (userId: string, playlistId: string): any => {
    return http.get(
      `/music/playlist/favorite/isFavorited?userId=${userId}&playlistId=${playlistId}`
    );
  };

  const getPlaylistMusic = (playlistId: string): any => {
    return http.get(
      `/music/playlists/getMusicByPlaylistId?playlistId=${playlistId}`
    );
  };

  return {
    getRecommendPlaylists,
    postCreatePlaylist,
    getFavoritePlaylist,
    getUserPlaylists,
    getPlaylistDetail,
    postAddToFavorite,
    postRemoveFromFavorite,
    checkIsFavorite,
    getPlaylistMusic,
  };
};
